package controllerLayer;

import modelLayer.Product;
import DBLayer.*;


public class ProductCtr {

	private DbProduct dbproduct;
	
	public ProductCtr(DbProduct dbproduct) {
		this.dbproduct = dbproduct;
	}
	
	public Product searchById(int _productId)
	{
			return dbproduct.findProduct(_productId, true);	
	}
	public boolean registerNewProduct(int _productId, String _name, double _purchasePrice, double _salesPrice, double _rentPrice, String _countryOfOrigin, String _productType, String _supName, int _locationId, String _productDescription)
	{
		boolean succes = false;
		
		Product temproduct = new Product(_productId, _name, _purchasePrice,_salesPrice,_rentPrice,_countryOfOrigin,_productType, _supName,_locationId,_productDescription);
		dbproduct.insertProduct(temproduct);
		
		if(searchById(_productId) != null)
		{
			succes = true;
		}
		return succes;
	}
	public boolean updateProduct(int _productId, String _name, double _purchasePrice, double _salesPrice, double _rentPrice, String _countryOfOrigin, String _productType, String _supName, int _locationId, String _productDescription)
	{
		boolean succes = false;
		Product temProduct =  searchById(_productId);
		
		temProduct.setName(_name);
		temProduct.setPurchasePrice(_purchasePrice);
		temProduct.setSalesPrice(_salesPrice);
		temProduct.setRentPrice(_rentPrice);
		temProduct.setCountryOfOrigin(_countryOfOrigin);
		temProduct.setProductType(_productType);
		temProduct.setSupName(_supName);
		temProduct.setLocationId(_locationId);
		temProduct.setProductDescription(_productDescription);
		
		dbproduct.updateProduct(temProduct);
		
		if(searchById(_productId).getName().equalsIgnoreCase(_name))
		{
			succes = true;
		}
		return succes;
	}

 
	
}
	

	
	
	
	


